use crate::kernel::x86_64::{gdt::GDTEntry, idt::IDT};

#[repr(packed)]
pub struct BootInfo {
    pub mib: ModeInfoBlock,
    pub cspm: u16,
    pub cslm: u16,
    pub ds: u16,
    pub gdt: [GDTEntry; 256],
    pub idt: IDT,
    pub mm_entries_num: u32,
    pub mm_buffer: u32,
}

#[repr(C, packed)]
#[derive(Copy, Clone)]
pub struct ModeInfoBlock {
    pub mode_attributes: u16,
    pub win_a_attributes: u8,
    pub win_b_attributes: u8,
    pub win_granularity: u16,
    pub win_size: u16,
    pub win_a_segment: u16,
    pub win_b_segment: u16,
    pub win_func_ptr: u32,
    pub bytes_per_scan_line: u16,
    pub x_resolution: u16,
    pub y_resolution: u16,
    pub x_char_size: u8,
    pub y_char_size: u8,
    pub number_of_planes: u8,
    pub bits_per_pixel: u8,
    pub number_of_banks: u8,
    pub memory_model: u8,
    pub bank_size: u8,
    pub number_of_image_pages: u8,
    pub reserved1: u8,
    pub red_mask_size: u8,
    pub red_field_position: u8,
    pub green_mask_size: u8,
    pub green_field_position: u8,
    pub blue_mask_size: u8,
    pub blue_field_position: u8,
    pub rsvd_mask_size: u8,
    pub rsvd_field_position: u8,
    pub direct_color_mode_info: u8,
    pub phys_base_ptr: u32,
    pub reserved2: u32,
    pub reserved3: u16,
    pub lin_bytes_per_scan_line: u16,
    pub bnk_number_of_image_pages: u8,
    pub lin_number_of_image_pages: u8,
    pub lin_red_mask_size: u8,
    pub lin_red_field_position: u8,
    pub lin_green_mask_size: u8,
    pub lin_green_field_positiondb: u8,
    pub lin_blue_mask_size: u8,
    pub lin_blue_field_position: u8,
    pub lin_rsvd_mask_size: u8,
    pub lin_rsvd_field_position: u8,
    pub max_pixel_clock: u32,
    pub reserved4: [u8; 190usize],
}

pub fn get_bootinfo() -> &'static mut BootInfo {
    let p = 0x10_0000 as *mut BootInfo;
    unsafe { &mut *p }
}
